package com.holly.mapper;

import com.holly.pojo.Emp;
import com.holly.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author holly
 * @create 2025-06-29 16:51
 */
@Mapper
public interface EmpMapper {

    List<Emp> list(EmpQueryParam param);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
            "values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);

    @MapKey("ops")
    List<Map<String,Object>> countEmpJobData();

    @MapKey("gender")
    List<Map> countEmpGenderData();

    List<Emp> listAllEmp();

    @Select("select id from emp where dept_id = #{id}")
    List<Integer> getEmpByDeptId(Integer id);

    @Select("select id,username,name from emp where username = #{username} and password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);


    //原始分页查询
    /**
     * 查询总记录数
     * @return
     */
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id")
//    public Long count();

    /**
     * 分页查询所有员工信息
     * @return
     */
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
//            "order by update_time desc limit #{start},#{pageSize}")
//    public List<Emp> list(Integer start, Integer pageSize);

    //优化分页查询PageHelper插件实现
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
    //        "order by update_time desc")
    //public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);
}
